package com.yuanluludev.lib_base.base

import com.yuanluludev.lib_base.ext.toastTipMiddle
import com.yuanluludev.lib_utils.util.TimeUtils

/**
 * yuanLulu
 * 常用于导航页
 */
abstract class BaseVMTwiceExitActivity<VM : BaseViewModel> : BaseVmActivity<VM>() {

    /**
     * 第一次按返回键的时间
     */
    private var lastTime: Long = 0

    /**
     * 处理点击返回键
     */
    override fun onBackPressed() = twiceBackExit()

    /**
     * 两次点击退出应用
     */
    private fun twiceBackExit() {
        val currentTime = TimeUtils.getNowMills()
        if (currentTime - lastTime < 2000) {
            moveTaskToBack(true)
        } else {
            "再按一次退出".toastTipMiddle()
            lastTime = currentTime
        }
    }

}